package com.demo.controller;


import com.demo.dto.AddIntegralDto;
import com.demo.service.UserService;
import com.demo.utils.ResponseResult;
import com.demo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;



    //根据班级ID查询所有的学生
    @GetMapping("/findByClassId")
    public ResponseResult findByClassId(HttpSession session){

        User user = (User) session.getAttribute("user");

        return userService.findByClassId(user.getClassId());
    }
    //为用户添加积分
    @PostMapping("/addIntegral")
    public ResponseResult addIntegral(@RequestBody AddIntegralDto dto){

        return userService.addIntegral(dto);

    }
    @GetMapping("/resetGScoreByGroupId/{classId}")
    public ResponseResult resetGScoreByGroupId(@PathVariable Integer classId){
        return userService.resetGScoreByGroupId(classId);
    }

}
